﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Input;
using Dominion.Core;
using Dominion.WPF;
using Dominion.WPF.Commands;
using Dominion.WPF.Models;
using Dominion.WPF.Services;
using System.Windows;



namespace Dominion.WPF.ViewModels
{
    /// <summary>
    /// ViewModel pour MainWindow
    /// </summary>
    public class MainWindowViewModel : ViewModelBase
    {

        #region Constructors

        public MainWindowViewModel()
            : base()
        {

        }

        #endregion

        BankViewModel bankViewModel = new BankViewModel();
        public BankViewModel BankViewModel
        {
            get
            {
                return bankViewModel;
            }
        }

        PlayerViewModel playerViewModel = new PlayerViewModel();
        public PlayerViewModel PlayerViewModel
        {
            get
            {
                return playerViewModel;
            }
        }

        GameControlViewModel gameControlViewModel = new GameControlViewModel();
        public GameControlViewModel GameControlViewModel
        {
            get
            {
                return gameControlViewModel;
            }
        }


        #region Commands

        private RelayCommand endTurnCommand;
        public ICommand EndTurnCommand
        {
            get
            {
                if (UserContext.CurrentGame == null) return null;
               
                if (endTurnCommand == null)
                    endTurnCommand = new RelayCommand(EndTurn,
                        (x) => UserContext.CurrentPlayer.Cards.Hand.Any()
                        );
                return endTurnCommand;

            }
        }

      


     

        public void EndTurn(object o)
        {
            UserContext.CurrentPlayer.EndTurn();
        }

        #endregion


        public Card CarteAJouer { get; set; }

        public Player Player
        {
            get
            {
                return UserContext.CurrentPlayer;
            }
        }


        private ICollectionView messages;
        public ICollectionView Messages
        {
            get
            {
                if (UserContext.CurrentGame == null) return null;
               
                if (messages == null)
                    messages = CollectionViewSource.GetDefaultView(UserContext.CurrentGame.Messages);
                return messages;
            }
        }


        public IEnumerable Users
        {
            get
            {
                return UserContext.CurrentGame.Players;
            }
        }


    }
}
